<template>
  <el-select @visible-change="renovate($event)" v-model="value" placeholder="请选择" size="mini" style="float:right" >
    <el-option
      v-for="item in projectList"
      :key="item.id"
      :label="item.projectName"
      :value="item.id">
    </el-option>
  </el-select>
</template>

<script>
  export default {
    // inject:["reload"],
    watch:{
      value :function(value){
        this.$store.dispatch('getNewProjectId',value)
        localStorage.setItem("projectId",this.$store.getters.getProjectId)
        // this.reload();
        // location.reload();
      }
    },
    data() {
      return {
        value: '',
        projectList:'',
      }
    },
    created(){
      this.getProjectList(true);
    },
    methods:{
      renovate(callback){
        console.log(callback)
        if (callback){
          this.getProjectList(false);
        }
      },
      cs(test){
        console.log(test);
      },
      getProjectList(isTrue){
        this.$project
          .projectList()
          .then((res) => {
            if (res.code == 200) {
              this.projectList = res.data;
              // this.value = this.$store.getters.getProjectId
              // this.value = this.projectList[0].id;
              if (isTrue){
                this.value = this.projectList[0].id;
              }
            }
          })
          .catch((res) => {
            console.log(res);
          });
      }
    }
  }
</script>
